//
//  OSNetworkRequest.m
//  OSChina
//
//  Created by 林涛 on 14/12/25.
//  Copyright (c) 2014年 林涛. All rights reserved.
//

#import "OSNetworkRequest.h"
#import "OSNetworkService.h"
#import "XMLDictionary.h"

@interface OSNetworkService()
@end
@implementation OSNetworkRequest
//http://www.oschina.net/openapi/docs/news_list 接口地址
+ (void)newListRequestWithCount:(NSString *)count
                        catalog:(NSString *)catalog
                      pageIndex:(NSString *)pageIndex
                        success:(SucceedBlock)successBlock
                        failure:(void (^)(NSError *error))failureBlock
{
    NSDictionary *param = @{@"catalog"  : catalog,
                            @"pageIndex": pageIndex,
                            @"pageSize ": count
                            };
    [OSNetworkService httpRequestWithParam:param requestPath:api_news_list success:^(id result) {
        if ([result isKindOfClass:[NSXMLParser class]]) {
            NSDictionary *dic = [NSDictionary dictionaryWithXMLParser:result];
            successBlock(dic);
        }
    } failure:^(NSError *error) {
        failureBlock(error);
    }];
}


//http://www.oschina.net/openapi/docs/news_detail 接口地址
+ (void)detailRequestWithURL:(NSString *)url
                    detailID:(NSString *)detailID
                     success:(SucceedBlock)successBlock
                     failure:(void (^)(NSError *error))failureBlock
{
    NSDictionary *param = @{@"id"  : detailID,
                            };
    [OSNetworkService httpRequestWithParam:param requestPath:url success:^(id result) {
        if ([result isKindOfClass:[NSXMLParser class]]) {
            NSDictionary *dic = [NSDictionary dictionaryWithXMLParser:result];
            successBlock(dic);
        }
    } failure:^(NSError *error) {
        failureBlock(error);
    }];
}


+ (void)blogListRequestWithCount:(NSString *)type
                        success:(SucceedBlock)successBlock
                        failure:(void (^)(NSError *error))failureBlock
{
    NSDictionary *param = @{@"type"  : type,
                            @"pageIndex": @"1",
                            @"pageSize":@"20"
                            };
    [OSNetworkService httpRequestWithParam:param requestPath:api_blog_list success:^(id result) {
        if ([result isKindOfClass:[NSXMLParser class]]) {
            NSDictionary *dic = [NSDictionary dictionaryWithXMLParser:result];
            successBlock(dic);
        }
    } failure:^(NSError *error) {
        failureBlock(error);
    }];
}


+ (void)answerLisRequestWithCount:(NSString *)count
                        catalog:(NSString *)user
                      pageIndex:(NSString *)pageIndex
                        success:(SucceedBlock)successBlock
                        failure:(void (^)(NSError *error))failureBlock
{
    NSDictionary *param = @{@"user"  : user,
                            @"pageIndex": pageIndex,
                            @"pageSize" : count
                            };
    [OSNetworkService httpRequestWithParam:param requestPath:api_post_list success:^(id result) {
        if ([result isKindOfClass:[NSXMLParser class]]) {
            NSDictionary *dic = [NSDictionary dictionaryWithXMLParser:result];
            successBlock(dic);
        }
    } failure:^(NSError *error) {
        failureBlock(error);
    }];
}

+ (void)tweetLisRequestWithCount:(NSString *)count
                          catalog:(NSString *)catalog
                        pageIndex:(NSString *)pageIndex
                          success:(SucceedBlock)successBlock
                          failure:(void (^)(NSError *error))failureBlock
{
    NSDictionary *param = @{@"catalog"  : catalog,
                            @"pageIndex": pageIndex,
                            @"pageSize" : count
                            };
    [OSNetworkService httpRequestWithParam:param requestPath:api_tweet_list success:^(id result) {
        if ([result isKindOfClass:[NSXMLParser class]]) {
            NSDictionary *dic = [NSDictionary dictionaryWithXMLParser:result];
            successBlock(dic);
        }
    } failure:^(NSError *error) {
        failureBlock(error);
    }];
}

+ (void)loginWithUserName:(NSString *)userName
                 password:(NSString *)loginPassword
                  success:(SucceedBlock)successBlock
                  failure:(void (^)(NSError *error))failureBlock
{
    NSDictionary *param = @{@"username"  : userName,
                            @"pwd": loginPassword,
                            @"keep_login" : @"1"
                            };
    [OSNetworkService httpRequestWithParam:param requestPath:api_login_validate success:^(id result) {
        if ([result isKindOfClass:[NSXMLParser class]]) {
            NSDictionary *dic = [NSDictionary dictionaryWithXMLParser:result];
            successBlock(dic);
        }
    } failure:^(NSError *error) {
        failureBlock(error);
    }];

}


@end
